<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018\7\17 0017
 * Time: 11:29
 */
namespace model\admin;
use model;
class customerGroupModel extends model{


    public static function get_list( ){

        $sql = 'SELECT * FROM sh_customer_group';

        $query = self::$db->query( $sql );

        return $query->rows;
    }

    public static function info( $customer_group_id ){

        $sql = 'SELECT * FROM sh_customer_group where id=' .$customer_group_id ;

        $query = self::$db->query( $sql );

        return $query->row;

    }

    public static function create( $data ){

        $sql = "INSERT INTO sh_customer_group SET `name` = '" . $data['name'] . "',
                description = '" . $data['description'] . "',
                sort_order = '" . $data['sort_order'] . "'";

        self::$db->query( $sql );

        $last_id = self::$db->getLastId( );
        return $last_id;
    }

    public static function edit( $customer_group_id, $data ){

        $sql = "update sh_customer_group SET `name` = '" . $data['name']
            . "', description = '" . $data['description']
            . "', sort_order = '" . $data['sort_order']
            . "' where id=" . $customer_group_id;

        $query = self::$db->query( $sql );
        return $query->num_rows;

    }

    public static function delete( $customer_groups ){

        $ids = implode( ',', $customer_groups );
        $sql = "DELETE FROM sh_customer_group WHERE id IN ( " . $ids . " )";

        $query = self::$db->query( $sql );
        return $query->num_rows;

    }
}
